#include<bits/stdc++.h>
using namespace std;
int ans,maxx;
double t,n,m,l,v,a[3001],b[3001],c[3001],s[3001];
double used[3001],p[3001],q[3001],f[3001],an[3001][3001];
void dfs(int x){
    if(x==m+1){
        int as=0;
        for(int i=1;i<=m;i++){
            if(f[i]==1){
                for(int j=1;j<=n;j++){
                    if(an[j][i]==1){
                        as++;
                        break;
                    }
                }
            }
        }
        if(as==ans){
            int dw=0;
            for(int i=1;i<=m;i++){
                if(f[i]==0) dw++;
            }
            maxx=max(maxx,dw);
            cout<<maxx<<endl;
        }
        return;
    }
    f[x]=0;
    dfs(x+1);
    f[x]=1;
    dfs(x+1);
}
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>t;
    while(t--){
        ans=0;
        maxx=0;
        cin>>n>>m>>l>>v;
        for(int i=1;i<=n;i++){
            cin>>a[i]>>b[i]>>c[i];
            if(c[i]==0){
                if(b[i]>v){
                    s[i]=a[i];
                }
                else{
                    s[i]=1e9;
                }
                continue;
            }
            s[i]=(v*v-b[i]*b[i])/(2*c[i])+a[i];
        }
        for(int i=1;i<=m;i++){
            cin>>q[i];
            for(int j=1;j<=n;j++){
                if(c[j]>=0){
                    if(a[j]<q[i]&&s[j]<q[i]){
                        used[j]=1;
                        an[j][i]=1;
                    }
                }
                else{
                    if(a[j]<=q[i]&&s[j]>q[i]){
                        an[j][i]=1;
                        used[j]=1;
                    }
                }
            }
        }
        for(int i=1;i<=n;i++){
            if(used[i]==1) ans++;
        }
        dfs(1);
        cout<<ans<<" "<<maxx<<endl;
    }
    return 0;
}
